package com.hd.crdao.adapter;

import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.hd.crdao.R;
import com.hd.crdao.base.MyBaseAdapter;
import com.hd.crdao.bean.MyOrderBean;
import com.hd.crdao.config.Constants;
import com.hd.crdao.utils.StringUtils;
import com.hd.crdao.utils.UIUtils;
import com.hd.crdao.wrapper.GlideImageUtils;

import java.util.List;

/**
 *
 *@author Programming
 *@date 2017/6/5 0005
 */
public class MyOrderAdapter extends MyBaseAdapter<MyOrderBean.RowsBean> {

    public MyOrderAdapter(List<MyOrderBean.RowsBean> dataSets) {
        super(dataSets);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(UIUtils.getContext(), R.layout.item_myorder, null);
            holder = new ViewHolder();
            holder.mOrderNumber = (TextView) convertView.findViewById(R.id.order_number);
            holder.mOrderState = (TextView) convertView.findViewById(R.id.order_state);
            holder.mOrderCarpicture = (ImageView) convertView.findViewById(R.id.order_carpicture);
            holder.mOrderCardesc = (TextView) convertView.findViewById(R.id.order_cardesc);
            holder.mOrderCarcolor = (TextView) convertView.findViewById(R.id.order_carcolor);
            holder.mOrderSingleprice = (TextView) convertView.findViewById(R.id.order_singleprice);
            holder.mOrderCarsum = (TextView) convertView.findViewById(R.id.order_carsum);
            holder.mOrderSumprice = (TextView) convertView.findViewById(R.id.order_sumprice);
            holder.mContactforservice = (Button) convertView.findViewById(R.id.contactforservice);
            //  holder.mPayearnestmoney = (Button) convertView.findViewById(R.id.payearnestmoney);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        MyOrderBean.RowsBean rowsBean = mDataSets.get(position);
        holder.mOrderNumber.setText(rowsBean.getNoId());

        holder.mOrderCardesc.setText(rowsBean.getNewCar().getVehConfig().getVcTypenme());
        holder.mOrderCarcolor.setText(rowsBean.getNoColour());
        holder.mOrderSingleprice.setText("" + rowsBean.getNewCar().getNcPubprice() + "万");
        holder.mOrderCarsum.setText("x" + rowsBean.getNoOrdnum());
        holder.mOrderSumprice.setText("合计" + StringUtils.doubleToString(rowsBean.getNoAmount()) + "万");
        //设置状态
        int parseInt = Integer.parseInt(rowsBean.getNoStatus());
        switch (parseInt) {
            case 0:
                holder.mOrderState.setText("待付定金");
                break;
            case 1:
                holder.mOrderState.setText("已付定金");
                break;
            case 2:
                holder.mOrderState.setText("已付全款");
                break;
            default:
                holder.mOrderState.setText("已发车");
                break;

        }
      //  ALog.d(rowsBean.getNewCar().getPhotoPath());
        GlideImageUtils.loadImage(Constants.IMAGEURL + rowsBean.getNewCar().getPhotoPath(),R.drawable.logo_moren_2x,holder.mOrderCarpicture);
        holder.mContactforservice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + UIUtils.getResources().getString(R.string.companyTelephone)));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                UIUtils.getContext().startActivity(intent);
            }
        });

        return convertView;
    }

    class ViewHolder {
        TextView mOrderNumber;
        TextView mOrderState;
        ImageView mOrderCarpicture;
        TextView mOrderCardesc;
        TextView mOrderCarcolor;
        TextView mOrderSingleprice;
        TextView mOrderCarsum;
        TextView mOrderSumprice;
        Button mContactforservice;
        // Button mPayearnestmoney;

    }
}
